//
//  FFServicerListVM.m
//  LLWallet
//
//  Created by tt on 2020/9/15.
//

#import "FFServicerListVM.h"
#import "FFServicerListCell.h"

@interface FFServicerListVM ()

@property(nonatomic,strong) NSArray<FFServicerResp*> *servicers;

@end

@implementation FFServicerListVM

- (NSArray<NSDictionary *> *)tableSectionMaps {
    if(!self.servicers ||self.servicers.count<=0) {
        return nil;
    }
    NSMutableArray *items = [NSMutableArray array];
    for (FFServicerResp *resp in self.servicers) {
        [items addObject:@{
               @"class": FFServicerListModel.class,
               @"name": resp.name?:@"",
               @"avatar": [WKAvatarUtil getAvatar:resp.uid],
               @"onClick":^{
            [[WKApp shared] invoke:WKPOINT_CONVERSATION_SHOW param:[[WKChannel alloc] initWith:resp.uid channelType:WK_PERSON]];
               }
        }];
    }
    return @[
        @{
             @"height":@(10.0f),
             @"items":items,
        }
    ];
}

- (void)requestData:(void (^)(NSError * _Nullable))complete {
    __weak typeof(self) weakSelf = self;
    [[WKAPIClient sharedClient] GET:@"user/customerservices" parameters:nil model:FFServicerResp.class].then(^(NSArray<FFServicerResp*> *items){
        weakSelf.servicers = items;
        complete(nil);
    }).catch(^(NSError *error){
        complete(error);
    });
}

@end

@implementation FFServicerResp

+ (WKModel *)fromMap:(NSDictionary *)dictory type:(ModelMapType)type {
    FFServicerResp *resp = [FFServicerResp new];
    resp.uid = dictory[@"uid"];
    resp.name = dictory[@"name"];
    return resp;
}

@end
